var pageAll;
var page = 1;
var isLoading = true;
var isInit = true;
apiready = function() {

	getData();


};


function getData() {
	$api.getServerUrl(function(serverUrl) {
		isLoading = true;
		$api.do_get("/api/products/list?rows=10&page=" + page, function(result) {

			var html = '';
			pageAll = result.total;

			if (!result) {
				html += '<div class="introduce_info"><span>暂无报团信息...</span></div>';
				return;
			}
			var item = result.rows;
			item.forEach(function(item) {
				item.sgImg = serverUrl + "/files/" + item.sgImg;
				$api.log(item.sgImg);
			});

			$api.crateDom("_homeGroup.html", item, function(resultHtml) {

				$("#tuanList").append(resultHtml);
				if (isInit) {
					isInit = false;
					api.addEventListener({

						name: 'scrolltobottom',
						extra: {
							threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
						}

					}, function(ret, err) {
						console.error("page:" + page);
						if (page <= pageAll && !isLoading) {
							page+=1;
							getData();
						}
					});
				}
				isLoading = false;
			});
		});



	});

}